package com.hspedu.exception_;

/**
 * @Author Stringzhua
 * @Date 2024/3/7 21:34
 * description:
 */
public class ClassCastException_ {
    public static void main(String[] args) {
        A b = new B();//向上转型
        B b2 = (B) b;//向下转型-->ok

        C c2 = (C) b;//这里会抛出ClassCastException
//        Exception in thread "main" java.lang.ClassCastException: com.hspedu.exception_.B cannot be cast to com.hspedu.exception_.C
//        at com.hspedu.exception_.ClassCastException_.main(ClassCastException_.java:13)
    }
}

class A {
}

class B extends A {
}

class C extends A {
}

